<template>
	<view class="u-page">
		<zb-dropdown-menu style="width: 100%" active-color="#00aaff">
			<zb-dropdown-item name="first" :options="option" v-model="value1" @change="change1"></zb-dropdown-item>
			<zb-dropdown-item name="two" :options="option2" v-model="value2" @change="change2"></zb-dropdown-item>
			<zb-dropdown-item name="three" :options="option3" v-model="value3" @change="change3"></zb-dropdown-item>
		</zb-dropdown-menu>
		<u-calendar :show="show" :mode="mode" :monthNum="monthNum" :maxDate="maxDate" :minDate="minDate" :defaultDate="defaultDate" @confirm="confirm" @close="datedel"></u-calendar>
		<u-cell-group>
				<u-cell icon="file-text" :border="false"  :title="title"></u-cell>
			</u-cell-group>
	   <div v-if="list1<1">
		   <u-empty
		           mode="list"
		           icon="http://cdn.uviewui.com/uview/empty/list.png"	
		   >
		   </u-empty>
	   </div>
		<div v-else>
			<u-list @scrolltolower="scrolltolower" style="zoom: 110%;">
				<u-list-item v-for="(item, index) in indexList" :key="index">
				<!-- 	<view class="uni-card__header-extra" @click="onClick('extra')">
						<text class="uni-card__header-extra-text">{{ extra }}</text>
					</view> -->
						<uni-card :title="item.equipment" sub-title="设备名" extra="删除" @click="more(index,item.id,$event)" >
							<text>维护人：</text><text>{{item.manage_name}}</text>
							<br>
							<div v-if="item.rank==1">
								<text>维护类型：</text><text>车辆维护</text>
							</div>
							<div v-if="item.rank==2">
								<text>维护类型：</text><text>站台维护</text>
							</div>
							<text>维护等级：</text><text>{{item.category}}级</text>
							<br>
							<text>所属车队：</text><text>{{item.org_name}}</text>
							<br>
							<text>维护时间：</text><text>{{$u.timeFormat(item.create_time, 'yyyy年mm月dd日')}}</text>
							<br>
							<text>审核时间：</text><text>{{$u.timeFormat(item.finish_time, 'yyyy年mm月dd日')}}</text>
							<br>
						
							<div v-if="item.status==0">
								
								<text>状态：</text><view style="width: 3rem;display: inline-block;"><u-tag text="未审核" plain size="mini"></u-tag></view>
								
								 <!-- <text>审核状态：</text><u-tag text="已完成待审核" type="warning" plain size="mini" style="width: 5.3rem;display: inline-block;"></u-tag> -->
							</div>
							<div v-else-if="item.status==1">
								<text>状态：</text><view class="" style="width: 4rem;display: inline-block;"><u-tag text="审核通过" type="success" plain size="mini"></u-tag></view>
							</div>
							<div v-else-if="item.status==2">
								<text>状态：</text><view class="" style="width: 5.5em;display: inline-block;"><u-tag text="审核不通过" type="warning" plain size="mini"></u-tag></view>

							</div>
							<text>拍照：</text><u--image width="50" height="50" :src="item.img" @click="imgListPreview(item.img)" mode="widthFix"></u--image>
						</uni-card>
				</u-list-item>
			</u-list>
		</div>
<u-modal :show="off" showCancelButton :title="titleo" @confirm="del" @cancel="cancel" :content='content'></u-modal>
	<u-notify ref="uNotify" message="Hi uView"></u-notify>
	</view>
</template>

<script>
import indexList from '../../uni_modules/uview-ui/libs/config/props/indexList';
import store from '@/store/index.js'
import { onLoad } from '../../uni_modules/uview-ui/libs/mixin/mixin';
	export default {
		data() {
			return {
				off:false,
				showdel:false,
				titleo:'删除',
				content:'确认删除后，将无法恢复',
				indexList: [],
				option: [{
						text: '全部',
						value: ''
					},
					{
						text: '未审核',
						value: 0
					},
					{
						text: '审核通过',
						value: 1
					},
					{
						text: '审核不通过',
						value: 2
					},	
				],
				option2: [{
						text: '日期降序',
						value: "create_time desc"
					},
					{
						text: '日期升序',
						value: "create_time asc"
					},
					// {
					// 	text: '自定义日期范围',
					// 	value: ""
					// },
				],
				option3: [
					{
						text: '所有时间',
						value: "所有时间"
					},
					{
						text: '自定义日期范围',
						value: "自定义日期范围"
					},
				],
				title:'',
				value1: '',
				value2: '',
				value3: '',
				value6:0,
				page:0,
				list1:1,
				userid: '',
				sever:store.state.sever,
				show: false,
				mode: 'range',
				monthNum:'13',
				minDate:'2022-06-01',
				maxDate: uni.$u.timeFormat(this.timestamp, 'yyyy-mm-dd'),
				defaultDate:[uni.$u.timeFormat(this.timestamp, 'yyyy-mm-dd')],
				time:'',
				delid:'',
				delindex:'',
				count:'',
			}
		},
		// created(){
		// 	alert(123);
		// },
		onLoad(option) {
			this.userid=store.state.userinfo.userid;
			this.name=store.state.userinfo.nickname;
			// this.page--;
			// this.checklogin();
			// this.userid = option.userid;
			this.loadmore();
			
		},
		onShow: function() {
		            uni.$once('query' ,(query)=>{
						//console.log();
						this.indexList[query.index].condition=1;
		            });
		        },
		mounted() {
			this.value1 = this.option[0]['value'];
			this.value2 = this.option2[0]['value'];
			this.value3 = this.option3[0]['value'];
			// alert(this.list1);
		},
		methods: {
			checklogin(){
				var userid = uni.getStorageSync("userid");
				this.userid = userid;
				console.log(userid);
				console.log(this.userid);
				if (typeof(userid)=="undefined" || userid=='' || userid==null)
				{
				  uni.navigateTo({
				  	url: "/pages/index/index"
				  });
				}
			},
			imgListPreview(url){
			                var urlList = []
			                urlList.push(url)  //push中的参数为 :src="item.img_url" 中的图片地址
			                uni.previewImage({
			                    indicator:"number",
			                    loop:true,
			                    urls: urlList
			                })
			            },
			confirm(e) {
				// console.log(e);
				// console.log( Date.parse(e[0])/1000);
				// console.log(Date.parse(e[e.length-1])/1000);
				this.show=false;
				//this.time='create_time between ? and ?';
				this.time=[Date.parse(e[0])/1000,Date.parse(e[e.length-1])/1000];
				this.time=this.time.join();
				this.search();
			},
			datedel(){
				this.show=false;
			},
			change1(item) {
				console.log(item);
				this.search();
			},
			change2(item) {
				console.log(item);
				if(this.indexList.length>0){
				   this.search()	
				}
				
			},
			change3(item) {
				// alert(this.indexList.length);
				console.log(item);
				if(item.text=="自定义日期范围"){
					this.show=true;
					return
				}else{
					// if(this.indexList.length>0){
						this.time='';
					   this.search()	
					// }
				}
				// if(this.indexList.length>0){
				// 	this.time='';
				//    this.search()	
				// }
				
			},
			scrolltolower() {
				this.loadmore()
			},
			search(){
				
				this.page=0;
				if(this.indexList.length>0){
					this.indexList=[]
				}
			//this.indexList=[];
				this.loadmore()
			},
			loadmore() {
				if(this.value2==""){
					this.value2="create_time desc";
				}
				// alert(this.value2);
				this.page++;
				// this.indexList=[];
				var page = this.page;
				var limit = 5;
				// if(page>1){
				// 	return;
				// }
				console.log(this.time);
				uni.$u.http.get(this.sever+'/api.v1/safeList?limit='+limit+'&page='+page+"&userid="+this.userid+"&condition="+this.value1+"&order="+this.value2+"&time="+this.time,).then(res => {
					if(res.data.Status==1){
						 	let arr = res.data.Data;
						 	for(let item of arr){
								if(item.img!=null&&item.img!=''&&item.img!=undefined){
											item.img=this.sever+item.img;
								}
								this.indexList.push(item);
						 	}
							console.log(this.indexList);
						 	this.list1=1;
							this.count=res.data.Total;
				            this.title="共"+this.count+"条记录";
						 }else{
							 if(this.indexList.length<1){
								 this.list1=0;
							 }else{
								 this.page--;
								 this.list1=1;
							 }
						 }
					
				}).catch(err => {
				
				})
			
				// for (let i = 0; i < 30; i++) {
				// 	this.indexList.push()
				// }
			},
			listdetail(index){
				alert(index);
			},
			more(index,id,e){
				console.log(e);
				if(e=='extra'){
					this.off=true;
					this.delid=id;
					this.delindex=index;
				}
				 // console.log(this.indexList[index].condition);
				 //  this.indexList[index].condition=2;
				// uni.navigateTo({
					
				// 	url: "/pages/dtest/index?id="+id+"&index="+index,
				// });
				
			},
			cancel(){
				this.off=false;
				this.delid='';
				this.delindex='';
			},
			del(){
				uni.request({
				    url: this.sever+'/api.v1/safeDel', //仅为示例，并非真实接口地址。
					method: 'GET',
				    data: {
				        manager: this.userid,
						id:this.delid,
				    },
				    success: (res) => {
						if(res.data.Status==1){
							this.$refs.uNotify.show({
							           top: 0,
							           type: 'error',
							           color: 'white',
							           bgColor: 'green',
							           message: '删除成功',
							           duration: 1000 * 1,
							           fontSize: 15,
							           safeAreaInsetTop:true
							       })
							this.indexList.splice(this.delindex, 1);
							this.count--;
							this.title="共"+this.count+"条记录";
							this.off=false;
						}else{
							 this.$refs.uNotify.show({
							            top: 0,
							            type: 'error',
							            color: 'white',
							            bgColor: 'red',
							            message: '删除失败',
							            duration: 1000 * 1,
							            fontSize: 15,
							            safeAreaInsetTop:true
							        })
									this.off=false;
						}
				    }
				});
			},
		}
	}
</script>